(load-file "~/.emacs.d/mi-emacs/plugin/cedet-1.0/common/cedet.el")
(require 'cedet)

(setq auto-save-hook nil);;水母方法，防止cedet卡住
;;minimun features, syntax and semantic information.Include:
;;semantic-idle-scheduler-mode' - Keeps a buffer's parse tree up to date.                         
;;semanticdb-minor-mode' - Stores tags when a buffer is not in memory.                            
;;semanticdb-load-ebrowse-caches' - Loads any ebrowse dbs created earlier
;;(semantic-load-enable-minimum-features)

;;code-helper include:
;;imenu' - Lists Semantic generated tags in the menubar.                                           
;;semantic-idle-summary-mode' - Show summary for the tag by code under point.  (intellisense)     
;;senator-minor-mode' - Semantic Navigator, and global menu for all features Semantic.            
;;semantic-mru-bookmark-mode' - Provides a switch-to-buffer like keybinding for tag names.
(semantic-load-enable-code-helpers)

;;gaudy include:
;;semantic-stickyfunc-mode' - Tracks current function in header-line                               
;;semantic-decoration-mode' - Decorate tags based on various attributes.                           
;;semantic-decoration-on-includes' - Decoration style for include files.                           
;;(global-semantic-idle-completions-mode 1) ;;Provide smart symbol auto-completion  at idle time
;;(semantic-load-enable-gaudy-code-helpers)


;;semantic-highlight-func-mode' - Highlight the current tag.                     
;;(global-semantic-idle-tag-highlight-mode 1);; Highlight the tag for symbol at pt.               
;;semantic-decoration-on-*-members' -color the background of private and protected methods.        
(which-func-mode t);; Display the current function in the mode line. 
;;(semantic-load-enable-excessive-code-helpers)


;;semantic-highlight-edits-mode' - Highlight text that changed since last parse.                  
(global-semantic-show-unmatched-syntax-mode 1);;Highlight lexical tokens failed to be parsed.    
(global-semantic-show-parser-state-mode 1) ;; Show the current buffer state via small indicators
;;(semantic-load-enable-semantic-debugging-helpers)


;;enable folding mode to collapse a definition into a single line
;;(global-semantic-tag-folding-mode)

(setq senator-minor-mode-name "SN")
(setq semantic-imenu-auto-rebuild-directory-indexes nil)
(global-srecode-minor-mode 1)
(global-semantic-mru-bookmark-mode 1)

(require 'semanticdb)
(global-semanticdb-minor-mode 1)

(require 'semantic-ia)

(require 'semantic-gcc)

 (setq-mode-local c-mode semanticdb-find-default-throttle
                  '(project recursive unloaded system ))

;; (custom-set-variables
;;  '(semantic-idle-scheduler-idle-time 3)
;; )

;;(require 'semanticdb-global)
;;(semanticdb-enable-gnu-global-databases 'c-mode)

(require 'semantic-lex-spp)
(global-ede-mode t)

(setq semanticdb-project-roots (list (expand-file-name "/")))

;;(require 'semanticdb-ectag)
;;(setq tags-file-name "/usr/include/TAGS")
;;(semantic-load-enable-secondary-exuberent-ctags-support)

(defconst cedet-system-lisp-include-dirs
  (list ".." "/home/tommy/.emacs.d/mi-emacs/plugin/emacs-23.1/lisp"))
(defconst cedet-user-include-dirs
  (list  ".." "../include" "../inc" "../common" "../public" "../main"
        "../.." "../../include" "../../inc" "../../common" "../../public"
  ))
(defconst cedet-win32-include-dirs
  (list "C:/MinGW/include"
        "C:/MinGW/include/c++/3.4.5"
        "C:/MinGW/include/c++/3.4.5/mingw32"
        "C:/MinGW/include/c++/3.4.5/backward"
        "C:/MinGW/lib/gcc/mingw32/3.4.5/include"
        "C:/Program Files/Microsoft Visual Studio/VC98/MFC/Include"))
(require 'semantic-c nil 'noerror)
(let ((include-dirs cedet-user-include-dirs))
  (when (eq system-type 'windows-nt)
    (setq include-dirs (append include-dirs cedet-win32-include-dirs)))
  (mapc (lambda (dir)
          (semantic-add-system-include dir 'c++-mode)
          (semantic-add-system-include dir 'c-mode))
        include-dirs)
  (mapc (lambda (dir)
          (semantic-add-system-include dir 'lisp-mode)
          (semantic-add-system-include dir 'emacs-lisp-mode))
        cedet-system-lisp-include-dirs)
)


;; customisation of modes
(defun my-cedet-hook ()
 (local-set-key "\C-cm"  'semantic-ia-complete-symbol-menu)
 (local-set-key "\C-c\\" 'semantic-ia-complete-symbol)
 ;;
 (local-set-key "\C-c[" 'semantic-complete-analyze-inline)
 (local-set-key "\C-c]" 'semantic-decoration-include-visit)
 
 (local-set-key "\C-cj" 'semantic-ia-fast-jump)
 (local-set-key "\C-ct" 'semantic-mrub-switch-tags)
 (local-set-key "\C-cq" 'semantic-ia-show-doc)
 (local-set-key "\C-co" 'semantic-ia-show-summary)
 (local-set-key "\C-cr" 'semantic-symref)
 ;; for senator
 (local-set-key "\C-c\-" 'senator-fold-tag)
 (local-set-key "\C-c\=" 'senator-unfold-tag)
;;(local-set-key "." 'semantic-complete-self-insert)
;;(local-set-key ">" 'semantic-complete-self-insert)
)
 
(add-hook 'c-mode-hook 'my-cedet-hook)
(add-hook 'c++-mode-hook 'my-cedet-hook)
(add-hook 'lisp-mode-hook 'my-cedet-hook)
(add-hook 'emacs-lisp-mode-hook 'my-cedet-hook)
 
(defun my-c-mode-header-switch-hook ()
 (local-set-key "\C-c\C-t" 'eassist-switch-h-cpp)
)
(add-hook 'c-mode-hook 'my-c-mode-header-switch-hook)
(add-hook 'c++-mode-hook 'my-c-mode-header-switch-hook)

(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("__END_NAMESPACE_STD" . ""))
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("__BEGIN_NAMESPACE_STD" . ""))
;;(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("__BEGIN_NAMESPACE_STD" . ""))
;;(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("__BEGIN_" . ""))

(setq cdecl-project 
   (ede-cpp-root-project "cdecl" 
         :file "/home/tommy/Project/C/expert/cdecl/configure.ac"
         :include-path '( "/parser" 
                          "/common"
                          "/main" )
;;         :system-include-path '("/usr/include")
;;         :spp-table '(("_TIME_H" . "1"))
))

